<template>
  <div>
    <el-form :model="form" :inline="true" label-width="auto" style="max-width: 80%">
      <el-form-item label="订单号：" style="width: 30%;">
        <el-input v-model="productionInfo.o_number" :readonly="true" />
      </el-form-item>
      <el-form-item label="生产计划：" style="width: 30%;">
        <el-input v-model="productionInfo.p_number" :readonly="true" />
      </el-form-item>
      <el-form-item label="计划开始时间：	" style="width: 30%;">
        <el-input v-model="productionInfo.plan_start" :readonly="true" />
      </el-form-item>
      <el-form-item label="计划结束时间：	" style="width: 30%;">
        <el-input v-model="productionInfo.plan_end" :readonly="true" />
      </el-form-item>

      <el-form-item label="" style="width: 30%;">
        <el-select v-model="modelSize" placeholder="显示设置" style="width: 240px" @change="changeDisplaySize">
          <el-option label="按月显示" value="月" />
          <el-option label="按天显示" value="天" />
          <el-option label="按天显示" value="天1" />
          <!-- <el-option label="按小时显示" value="时" /> -->
        </el-select>

        <el-button type="primary" @click="showAllGxSetting">排产设置</el-button>
        <!-- <el-button type="danger" @click="savePaichanInfo">保存排产信息</el-button> -->
      </el-form-item>
    </el-form>

    <el-dialog v-model="settingDlgVisible" title="" width="1280" :before-close="handleClose" draggable>
      <div style="padding: 10px 0;">
        <el-button type="primary" @click="importGoodsGxSetting">导入产品工序设定</el-button>
        <el-button type="danger" @click="clearPaichanDate">清空排产日期</el-button>
        <!-- <el-button type="primary">导入产品工序设定</el-button> -->
      </div>
      <el-table :data="gxFromData" style="width: 100%" row-key="id" border lazy default-expand-all
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
        <el-table-column prop="name" label="工序" header-align="center" width="200">
          <template #default="{ row }">
            <span v-if="row.type == 'gx'">{{ row.name }}</span>
            <span v-else>{{ row.name }}({{ row.num }})</span>
          </template>
        </el-table-column>
        <el-table-column prop="workerNum" label="上工序" header-align="center">
          <template #default="{ row }">
            <el-select v-model="row.prevGxId" placeholder="请选择" v-if="row.type == 'gx'" clearable
              @change="onPrevGxChange(row.id)">
              <el-option label="无" :value="0" />
              <template v-for="_goods in gxFromData">
                <template v-if="_goods.children[0].goodsId == row.goodsId">
                  <el-option v-for="gx in _goods.children" :key="gx.id" :label="gx.name" :value="gx.id" />
                </template>
              </template>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="workerNum" label="工人数量" header-align="center" width="100">
          <template #default="{ row }">
            <el-input v-if="row.type == 'gx'" v-model="row.workerNum" clearable @change="saveGxInfo(row.id)"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="workHourPerDay" label="工时/天" header-align="center" width="100">
          <template #default="{ row }">
            <el-input v-if="row.type == 'gx'" v-model="row.workHourPerDay" clearable
              @change="saveGxInfo(row.id)"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="finishNumPerHour" label="完成数/人/时" header-align="center" width="120">
          <template #default="{ row }">
            <el-input v-if="row.type == 'gx'" v-model="row.finishNumPerHour" clearable
              @change="saveGxInfo(row.id)"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="" label="工作量" header-align="center" width="80" align="center">
          <template #default="{ row }">
            <span v-if="row.workerNum && row.workHourPerDay && row.finishNumPerHour">{{ row.workerNum * row.workHourPerDay
              * row.finishNumPerHour }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="minInitNum" label="物料起始数" header-align="center" width="100">
          <template #default="{ row }">
            <el-input v-if="row.type == 'gx' && row.prevGxId > 0" v-model="row.minInitNum" clearable
              @change="saveGxInfo(row.id)"></el-input>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="minInitNum" label="开始日期" header-align="center" width="170">
          <template #default="{ row }">
            <el-date-picker v-if="row.type == 'gx'" v-model="row.startTime" type="date" style="width: 140px;"
              placeholder="请选择" @change="saveGxInfo(row.id)" />
          </template>
        </el-table-column>
        <el-table-column prop="minInitNum" label="结束日期" header-align="center" width="170">
          <template #default="{ row }">
            <el-date-picker v-if="row.type == 'gx'" v-model="row.endTime" type="date" style="width: 140px;"
              placeholder="请选择" @change="saveGxInfo(row.id)" />
          </template>
        </el-table-column>
        <el-table-column prop="minInitNum" label="" header-align="center">
          <template #default="{ row }">
            <el-checkbox v-if="row.type == 'gx'" v-model="row.lockDate" label="锁定" :true-value="1" :false-value="0"
              @change="saveGxInfo(row.id)" />
          </template>
        </el-table-column>
      </el-table>

      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="saveSetting">
            保存
          </el-button>
        </div>
      </template>
    </el-dialog>
    <div class="gstc-wrapper" ref="gstcElement"></div>
  </div>
</template>

<script setup lang="ts">
import GSTC, { GSTCResult } from "gantt-schedule-timeline-calendar/dist/gstc.wasm.esm.min.js";
import { Plugin as TimelinePointer } from "gantt-schedule-timeline-calendar/dist/plugins/timeline-pointer.esm.min.js";
import { Plugin as Selection } from "gantt-schedule-timeline-calendar/dist/plugins/selection.esm.min.js";
import { Plugin as ItemResizing } from "gantt-schedule-timeline-calendar/dist/plugins/item-resizing.esm.min.js";
import { Plugin as ItemMovement } from "gantt-schedule-timeline-calendar/dist/plugins/item-movement.esm.min.js";
import { Plugin as Bookmarks } from "gantt-schedule-timeline-calendar/dist/plugins/time-bookmarks.esm.min.js";
import { Plugin as DependencyLines } from 'gantt-schedule-timeline-calendar/dist/plugins/dependency-lines.esm.min.js';

import "gantt-schedule-timeline-calendar/dist/style.css";
import { ref, onMounted, onBeforeUnmount } from "vue";
import axios from "axios";
import { ElMessage, ElMessageBox, ElPopconfirm } from "element-plus";
const GSTCID = GSTC.api.GSTCID;
const httpReq = axios.create({
  timeout: 15000,
})

const form = ref<any>({})
const paichanInfo = ref<any>({})
const productionInfo = ref<any>({})
const settingDlgVisible = ref(false)

const gxFromData = ref<any>([])
const gxSettingParm = ref<any>({ goodsId: 0, gxId: 0 })

var startTime = GSTC.api.date();
var endTime = GSTC.api.date().add(10, "day");

const key = ref<any>(0)
key.value = parseInt(getUrlParam("key") + "")

const API_URL = "/ExampleModule/ChengYuMES/MES_Paichan_Auto.aspx"
const modelSize = ref("天")

let gstc: GSTCResult, state;
const gstcElement = ref();

const colors = ['#E74C3C', '#DA3C78', '#7E349D', '#0077C0', '#07ABA0', '#0EAC51', '#F1892D'];
function getRandomColor(lockDate: number) {
  if (lockDate) {
    return "#e74c3c";
  }

  return "#45c77c"
  // return colors[Math.floor(Math.random() * colors.length)];
}

onMounted(() => {
  loadData()
});

onBeforeUnmount(() => {
  if (gstc) gstc.destroy();
});

function loadData() {
  httpReq.get(API_URL + "?action=getOrderPaichaDetail&p_id=" + key.value).then(resp => {

    productionInfo.value = resp.data.productionInfo
    paichanInfo.value = resp.data.paichanInfo

    const rows = {};
    const items = {};

    let ganttDeps = {}

    let start = GSTC.api.date().startOf("day").subtract(6, "day");
    for (let i = 0; i < paichanInfo.value.length; i++) {
      start = start.add(1, "day");
      let goodsInfo = paichanInfo.value[i]
      const id = GSTC.api.GSTCID("0-" + goodsInfo.goodsId);
      rows[id] = {
        id,
        expanded: true,
        label: `${goodsInfo.goodsName} (數量：${goodsInfo.num})`,
      }

      for (const gxKey in goodsInfo.gxInfo) {
        let gxInfo = goodsInfo.gxInfo[gxKey]
        let rowId = GSTC.api.GSTCID('gx-' + gxInfo.pgx_Id);

        if (GSTC.api.date(gxInfo.endTime) > endTime) {
          endTime = GSTC.api.date(gxInfo.endTime);
        }

        if (GSTC.api.date(gxInfo.startTime) < startTime) {
          startTime = GSTC.api.date(gxInfo.startTime);
        }

        rows[rowId] = {
          id: rowId,
          label: `${gxInfo.gxName}`,
          startTime: GSTC.api.date(gxInfo.startTime).startOf("day").format("YYYY-MM-DD"),
          endTime: GSTC.api.date(gxInfo.endTime).startOf("day").format("YYYY-MM-DD"),
          parentId: id,
          expanded: false,
          vacations: [],
          visible: true,
        }

        items[GSTC.api.GSTCID(gxInfo.pgx_Id)] = {
          id: GSTC.api.GSTCID(gxInfo.pgx_Id),
          label: `${gxInfo.gxName}`,
          rowId,
          style: { background: getRandomColor(gxInfo.lockDate) },
          progress: 40,
          dependant: [],
          time: {
            start: GSTC.api.date(gxInfo.startTime).startOf("day").valueOf(),
            end: GSTC.api.date(gxInfo.endTime).startOf("day").valueOf(),
          },
        }

        if (gxInfo.prevGxId) {

          if (!ganttDeps[gxInfo.prevGxId]) {
            ganttDeps[gxInfo.prevGxId] = []
          }
          ganttDeps[gxInfo.prevGxId].push(gxInfo.pgx_Id)
        }
      }

      // 半成品-子项
      for (const _index in goodsInfo.children) {
        let goodsInfo1 = goodsInfo.children[_index]
        let id1 = GSTC.api.GSTCID("1-" + goodsInfo1.goodsId);
        rows[id1] = {
          id1,
          expanded: true,
          parentId: id,
          label: `${goodsInfo1.goodsName} (數量：${goodsInfo1.num})`,
        }

        for (let gxKey1 in goodsInfo1.gxInfo) {
          let gxInfo1 = goodsInfo1.gxInfo[gxKey1]
          let rowId1 = GSTC.api.GSTCID('gx-' + gxInfo1.pgx_Id);

          if (GSTC.api.date(gxInfo1.endTime) > endTime) {
            endTime = GSTC.api.date(gxInfo1.endTime);
          }

          if (GSTC.api.date(gxInfo1.startTime) < startTime) {
            startTime = GSTC.api.date(gxInfo1.startTime);
          }

          if (gxInfo1.prevGxId) {
            if (!items[GSTCID(gxInfo1.prevGxId)].dependant) {
              items[GSTCID(gxInfo1.prevGxId)].dependant = []
            }

            items[GSTCID(gxInfo1.prevGxId)].dependant.push(GSTCID(gxInfo1.pgx_Id))
          }

          rows[rowId1] = {
            id: rowId1,
            label: `${gxInfo1.gxName}`,
            startTime: GSTC.api.date(gxInfo1.startTime).startOf("day").format("YYYY-MM-DD"),
            endTime: GSTC.api.date(gxInfo1.endTime).startOf("day").format("YYYY-MM-DD"),
            parentId: id1,
            expanded: false,
            vacations: [],
            visible: true,
          }

          items[GSTC.api.GSTCID(gxInfo1.pgx_Id)] = {
            id: GSTC.api.GSTCID(gxInfo1.pgx_Id),
            label: `${gxInfo1.gxName}`,
            rowId: rowId1,
            style: { background: getRandomColor(gxInfo1.lockDate) },
            progress: 100,
            dependant: [],
            time: {
              start: GSTC.api.date(gxInfo1.startTime).startOf("day").valueOf(),
              end: GSTC.api.date(gxInfo1.endTime).startOf("day").valueOf(),
            },
          }
        }
      }
    }

    for (const key in ganttDeps) {
      if (Object.prototype.hasOwnProperty.call(ganttDeps, key)) {
        const element = ganttDeps[key];
        element.forEach(function (_item) {
          items[GSTCID(key)].dependant.push(GSTCID(_item))
        })
      }
    }

    // console.log(items)


    resetGxFormData()

    /**
    * @type { import("gantt-schedule-timeline-calendar").Config }
    */
    const config = {
      licenseKey:
        "====BEGIN LICENSE KEY====\nXOfH/lnVASM6et4Co473t9jPIvhmQ/l0X3Ewog30VudX6GVkOB0n3oDx42NtADJ8HjYrhfXKSNu5EMRb5KzCLvMt/pu7xugjbvpyI1glE7Ha6E5VZwRpb4AC8T1KBF67FKAgaI7YFeOtPFROSCKrW5la38jbE5fo+q2N6wAfEti8la2ie6/7U2V+SdJPqkm/mLY/JBHdvDHoUduwe4zgqBUYLTNUgX6aKdlhpZPuHfj2SMeB/tcTJfH48rN1mgGkNkAT9ovROwI7ReLrdlHrHmJ1UwZZnAfxAC3ftIjgTEHsd/f+JrjW6t+kL6Ef1tT1eQ2DPFLJlhluTD91AsZMUg==||U2FsdGVkX1/SWWqU9YmxtM0T6Nm5mClKwqTaoF9wgZd9rNw2xs4hnY8Ilv8DZtFyNt92xym3eB6WA605N5llLm0D68EQtU9ci1rTEDopZ1ODzcqtTVSoFEloNPFSfW6LTIC9+2LSVBeeHXoLEQiLYHWihHu10Xll3KsH9iBObDACDm1PT7IV4uWvNpNeuKJc\npY3C5SG+3sHRX1aeMnHlKLhaIsOdw2IexjvMqocVpfRpX4wnsabNA0VJ3k95zUPS3vTtSegeDhwbl6j+/FZcGk9i+gAy6LuetlKuARjPYn2LH5Be3Ah+ggSBPlxf3JW9rtWNdUoFByHTcFlhzlU9HnpnBUrgcVMhCQ7SAjN9h2NMGmCr10Rn4OE0WtelNqYVig7KmENaPvFT+k2I0cYZ4KWwxxsQNKbjEAxJxrzK4HkaczCvyQbzj4Ppxx/0q+Cns44OeyWcwYD/vSaJm4Kptwpr+L4y5BoSO/WeqhSUQQ85nvOhtE0pSH/ZXYo3pqjPdQRfNm6NFeBl2lwTmZUEuw==\n====END LICENSE KEY====",
      plugins: [TimelinePointer(), Selection(),
      ItemResizing({
        events: {
          // onStart({ items }) {
          //   console.log('Resizing start', items.after);
          //   return items.after;
          // },
          // onResize({ items, vido }) {
          // },
          onEnd({ items }) {
            let rowId = items.after[0].rowId
            state.update(`config.list.rows.${rowId}`, (row: any) => {
              row.startTime = GSTC.api.date(items.after[0].time.start).startOf("day").format("YYYY-MM-DD")
              row.endTime = GSTC.api.date(items.after[0].time.end).startOf("day").format("YYYY-MM-DD")

              axios.post(API_URL + "?action=updateGxInfo", {
                form: {
                  "id": rowId.replace("gstcid-gx-", ""),
                  "startTime": row.startTime,
                  "endTime": row.endTime,
                }
              }).then(resp => {
                loadData()
              }).catch(e => {
                ElMessageBox.alert("出错了：" + JSON.stringify(e))
              })

              return row;
            });

            return items.after;
          }
        }
      }),
      ItemMovement({
        enabled: true,
        events: {
          onEnd({ items }) {
            let rowId = items.after[0].rowId
            let startTime = GSTC.api.date(items.after[0].time.start).startOf("day").format("YYYY-MM-DD")
            let endTime = GSTC.api.date(items.after[0].time.end).startOf("day").format("YYYY-MM-DD")

            axios.post(API_URL + "?action=updateGxInfo", {
              form: {
                "id": rowId.replace("gstcid-gx-", ""),
                "startTime": startTime,
                "endTime": endTime,
              }
            }).then(resp => {
              loadData()
            }).catch(e => {
              ElMessageBox.alert("出错了：" + JSON.stringify(e))
            })

            state.update(`config.list.rows.${rowId}.startTime`, startTime)
            state.update(`config.list.rows.${rowId}.endTime`, endTime)
            return items.after;
          },
        }
      }),
      Bookmarks(),
      DependencyLines({
        onLine: [
          (line) => {
            line.type = GSTC.api.sourceID(line.fromItem.id) === '3' ? 'smooth' : 'square';
            return line;
          },
        ],
      }),],
      locale: {
        name: "en",
        weekdays: "周日_周一_周二_周三_周四_周五_周六".split("_"),
        weekdaysShort: "日_一_二_三_四_五_六".split("_"),
        weekdaysMin: "日_一_二_三_四_五_六".split("_"),
        months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
        monthsShort: "一_二_三_四_五_六_七_八_九_十_十一_十二".split("_")
      },
      innerHeight: window.innerHeight - 180,
      list: {
        columns: {
          data: {
            [GSTC.api.GSTCID("label")]: {
              id: GSTC.api.GSTCID("label"),
              width: 200,
              data: "label",
              expander: true,
              header: {
                content: "项目",
              },
            },
            [GSTC.api.GSTCID("startTime")]: {
              id: GSTC.api.GSTCID("startTime"),
              width: 100,
              data: "startTime",
              expander: false,

              header: {
                content: "开始日期",
              },
            },
            [GSTC.api.GSTCID("endTime")]: {
              id: GSTC.api.GSTCID("endTime"),
              width: 100,
              data: "endTime",
              expander: false,
              header: {
                content: "结束日期",
              },
            },
          },
        },
        rows: rows,
      },
      chart: {
        time: {
          from: startTime.valueOf(),
          to: endTime.valueOf(),
          // onLevelDates: [onLevelDates],
        },
        items: items,
      },

      actions: {
        // "chart-timeline-items-row-item": [clickAction],
        // "list-column-row": [addAlertButtonAction],
      },
    }

    function clickAction(element: { addEventListener: (arg0: string, arg1: (event: any) => void) => void; }, data: { item: { id: any; }; }) {
      function onClick(event: any) {
        // data variable will be updated in update method below so it will be always actual
        alert(`Event ${data.item.id} clicked!`);
      }

      element.addEventListener("click", onClick);

      return {
        update(element: any, newData: any) {
          data = newData; // data from parent scope updated
        },

        destroy(element: { removeEventListener: (arg0: string, arg1: (event: any) => void) => void; }, data: any) {
          element.removeEventListener("click", onClick);
        },
      };
    }

    function addAlertButtonAction(el: { querySelector: (arg0: string) => any; }, mainData: {
      row: any; column: { id: string; };
    }) {
      function onClick() {

        gxSettingParm.value.gxId = mainData.row.id.replace("gstcid-gx-", "")
        gxSettingParm.value.goodsId = mainData.row.parentId.replace("gstcid-", "")

        gxFromData.value.forEach((_item, _index) => {
          if (_item.id == gxSettingParm.value.goodsId) {
            let _ch = _item

            _item.children.forEach((_c_item, _c_index) => {
              if (_c_item.id == gxSettingParm.value.gxId) {
                _ch.children = [_c_item]
                gxFromData.value = [_ch]
              }
            });
          }
        });

        settingDlgVisible.value = true
      }

      function addButton() {
        if (mainData.column.id !== GSTC.api.GSTCID("label")) return; // check if this column is a label
        const button = document.createElement("span");
        button.classList.add("my-alert-button");
        button.innerText = "设置";
        button.addEventListener("click", onClick);
        const label = el.querySelector(".gstc__list-column-row-content");
        if (label) label.appendChild(button);
      }

      function removeButton(el: { querySelector: (arg0: string) => any; }) {
        const button = el.querySelector(".my-alert-button");
        if (button) button.remove();
      }

      addButton();

      return {
        update(el: any, updatedData: any) {
          mainData = updatedData;
        },
        destroy(el: any, data: any) {
          removeButton(el);
        },
      };
    }

    state = GSTC.api.stateFromConfig(config as any);
    state.update("config.chart.time.zoom", 21);
    state.update('config.chart.time.autoExpandTimeFromItems', true);
    state.update('config.plugin.ItemMovement.allowItemsToGoOutsideTheArea', true);
    state.update('config.plugin.ItemResizing.allowItemsToGoOutsideTheArea', true);

    globalThis.state = state;
    gstc = GSTC({
      element: gstcElement.value,
      state,
    });
    globalThis.gstc = gstc;
  }).catch(e => {
    console.log(e)
    ElMessageBox.alert("数据加载失败！")
  })
}


function resetGxFormData() {
  gxFromData.value = []

  for (let i = 0; i < paichanInfo.value.length; i++) {
    let goodsInfo = paichanInfo.value[i]

    let goodsInfoRow = {
      "id": goodsInfo.goodsId,
      "name": goodsInfo.goodsName,
      "num": goodsInfo.num,
      "children": [] as any,
    }

    for (const gxKey in goodsInfo.gxInfo) {
      let gxInfo = goodsInfo.gxInfo[gxKey]

      goodsInfoRow.children.push({
        "id": gxInfo.pgx_Id,
        "goodsId": goodsInfo.goodsId,
        "name": gxInfo.gxName,
        "type": "gx",
        "finishNumPerHour": gxInfo.finishNumPerHour,
        "finishNum": gxInfo.finishNum,
        "gxNo": gxInfo.gxNo,
        "minInitNum": gxInfo.minInitNum,
        "num": gxInfo.num,
        "prevGxNo": gxInfo.prevGxNo,
        "workHourPerDay": gxInfo.workHourPerDay,
        "prevGxId": gxInfo.prevGxId,
        "workerNum": gxInfo.workerNum,
        "startTime": gxInfo.startTime,
        "endTime": gxInfo.endTime,
        "lockDate": gxInfo.lockDate,
      })
    }
    gxFromData.value.push(goodsInfoRow)
  }
}

function showAllGxSetting() {
  gxSettingParm.value.gxId = 0
  gxSettingParm.value.goodsId = 0
  settingDlgVisible.value = true
}

// function updateFirstRow() {
//   state.update(`config.list.rows.${GSTC.api.GSTCID("0")}`, (row: { label: string; }) => {
//     row.label = "Changed dynamically";
//     return row;
//   });
// }

// function changeZoomLevel() {
//   state.update("config.chart.time.zoom", 21);
// }

const handleClose = (done: () => void) => {
  // saveSetting()
  settingDlgVisible.value = false
  loadData()
}
function onPrevGxChange(gxId: number) {
  saveGxInfo(gxId)
}
function saveGxInfo(gxId: any) {

  gxFromData.value.forEach((goods: { children: any[]; }) => {
    goods.children.forEach((gx: any) => {
      if (gx.id == gxId) {
        if (!gx.prevGxId) {
          gx.prevGxId = null
        }
        if (!gx.startTime) {
          gx.startTime = null
        }
        if (!gx.endTime) {
          gx.endTime = null
        }
        if (!gx.minInitNum) {
          gx.minInitNum = null
        } else {
          gx.minInitNum = parseInt(gx.minInitNum)
        }

        axios.post(API_URL + "?action=updateGxInfo", { form: gx }).then(resp => {
          loadData()
          // ElMessageBox
          // .alert("更新成功")
        }).catch(e => {
          ElMessageBox.alert("出错了：" + JSON.stringify(e))
        })
      }
    });
  });
}

function saveSetting() {
  settingDlgVisible.value = false
}

function getUrlParam(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  var r = window.location.search.substr(1).match(reg); //匹配目标参数
  if (r != null) return unescape(r[2]);
  return null; //返回参数值
}

function savePaichanInfo() {
  axios.post(API_URL + "?action=savePaichanInfo&key=" + key.value, {}).then(resp => {
    ElMessageBox.alert("排产信息保存成功！")
  })
}

function changeDisplaySize() {
  let modelSizeVal = 22
  switch (modelSize.value) {
    case "月":
      modelSizeVal = 26
      break;
    case "天":
      modelSizeVal = 21
      break;
    case "天1":
      modelSizeVal = 22
      break;
    case "时":
      modelSizeVal = 16
      break;
    default:
      break;
  }
  state.update("config.chart.time.zoom", modelSizeVal);
}

function importGoodsGxSetting() {
  ElMessageBox.confirm(
    '将会覆盖现有设定！！您确认要导入产品中设定的工序信息么？',
    '提示',
    {
      confirmButtonText: '确定导入',
      cancelButtonText: '取消操作',
      type: 'warning',
    }
  )
    .then(() => {
      axios.post(API_URL + "?action=importGoodsGxSetting&key=" + key.value, {}).then(resp => {
        loadData()
        // ElMessageBox.alert("排产信息保存成功！")
      })
    })
    .catch(() => {
      // ElMessage({
      //   type: 'info',
      //   message: 'Delete canceled',
      // })
    })


}

function clearPaichanDate() {
  ElMessageBox.confirm(
    '已锁定的项目不会发生改变，其他项目将会覆盖现有设定！！您确认要清空排产日期么？',
    '提示',
    {
      confirmButtonText: '确定导入',
      cancelButtonText: '取消操作',
      type: 'warning',
    }
  )
    .then(() => {
      axios.post(API_URL + "?action=clearPaichanDate&key=" + key.value, {}).then(resp => {
        loadData()
        // ElMessageBox.alert("排产信息保存成功！")
      })
    })
    .catch(() => {
      // ElMessage({
      //   type: 'info',
      //   message: 'Delete canceled',
      // })
    })
}

</script>
<style type="sass" scoped>
.gstc-component {
  margin: 0;
  padding: 0;
}

.toolbox {
  padding: 10px;
}
</style>

<style>
.gstc__list-toggle {
  display: none;
}

.my-alert-button {
  cursor: pointer;
  width: 60px;
  height: 30px;
  float: right;
  padding-right: 10px;
  display: none;
  font-size: 12px;
  color: green;
}

.gstc__list-column-row-content:hover .my-alert-button {
  display: block;
}</style>
